package com.catchman.demo;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.catchman.demo.domain.User;
import com.catchman.demo.mapper.UserMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tk.mybatis.spring.annotation.MapperScan;

import java.util.List;

@SpringBootApplication
@MapperScan("com.catchman.demo.mapper") //通过使用@MapperScan可以指定要扫描的Mapper类的包的路径
public class DemoApplication implements ApplicationRunner {
    private static final Logger logger = LoggerFactory.getLogger(DemoApplication.class);

    @Autowired
    private UserMapper userMapper;

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        User user = userMapper.selectByPrimaryKey(1L);
        System.out.println(user);
        System.err.println("ceshirizhi");
        logger.error("测试日志！");


        // 分页使用: 获取第1页，1-10条数据
        PageHelper.startPage(2, 2);
        // 紧跟着的第一个select方法会被分页
        List<User> list = userMapper.selectAll();
        PageInfo pageInfo = new PageInfo<>(list);
        //获取总记录数
        long total = pageInfo.getTotal();
    }


}
